package com.jams.goodox.activity.common;

import android.content.Intent;
import android.widget.ListView;

import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.ChooseItem;
import com.jams.goodox.utils.StyleUtil;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

public class ChooseListActivity extends BaseActivity {

    @Bind(R.id.lv_choose)
    ListView lvChoose;
    private List<ChooseItem> chooseItems;
    public static final String TITLE = "TITLE";
    public static final String CHOOSE = "CHOOSE";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_choose_list;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this,getIntent().getStringExtra(TITLE));
        chooseItems = (List<ChooseItem>) getIntent().getSerializableExtra(CHOOSE);
        if (chooseItems == null) {
            chooseItems = new ArrayList<>();
        }
        lvChoose.setAdapter(new ListCommonAdapter<ChooseItem>(this, chooseItems, R.layout.choose_list_item) {
            @Override
            public void convert(ListCommonViewHolder helper, final ChooseItem item, int position) {
                helper.setText(R.id.tv_choose_name, item.getName())
                        .setViewVisible(R.id.iv_choose, item.isSelected())
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(int position) {
                                Intent intent = new Intent();
                                intent.putExtra(CHOOSE, item);
                                setResult(100, intent);
                                finish();
                            }
                        });

            }
        });
    }

}
